const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch({
    headless: false
  });
  const context = await browser.newContext();
  const page = await context.newPage();
  await page.goto('https://www.toutiao.com/?wid=1721287110226');
  page.on('load',async (page)=>{
    await page.getByLabel('头部').getByText('登录').click();
    await page.getByLabel('账密登录').click();
    await page.getByPlaceholder('手机号/邮箱').click();
    await page.getByPlaceholder('手机号/邮箱').fill('133 0248 6694');
    await page.getByPlaceholder('密码').click();
    await page.getByPlaceholder('密码').fill('abd3580');
    await page.getByLabel('协议勾选框').click();
    await page.getByRole('button', { name: '登录', exact: true }).click();
    const page1Promise = page.waitForEvent('popup');
    await page.getByRole('menuitem', { name: '写文章' }).click();
    const page1 = await page1Promise;
    await page1.locator('.byte-drawer-mask').click();
    await page1.getByText('草稿测试文章').click();
    await page1.getByPlaceholder('请输入文章标题（2～30个字）').click();
    await page1.getByPlaceholder('请输入文章标题（2～30个字）').fill('lalallala');
    await page1.getByText('测试文章。').click();
    await page1.locator('div').filter({ hasText: /^测试文章。$/ }).fill('when you are free, try to learn, do not spair yourself\n\n\n');
    await page1.getByRole('button', { name: '预览并发布' }).click();
    // await page1.locator('div').filter({ hasText: /^测试文章。ddddfsdfadsfasdfa$/ }).click();
    // await page1.locator('div').filter({ hasText: /^测试文章。ddddfsdfadsfasdfa$/ }).fill('测试文章。ddddfsdfadsfasdfa\n\ndfsdfafda\n\n\n');
    await page1.getByRole('button', { name: '确认发布' }).click();
    await page1.locator('button').filter({ hasText: '暂不认证' }).click();
  })
})();  
